{% extends "cmdb/mequipment/index.html" %}

{% block right_content %}
<div id="right_menu">
    <b class="modal-title">商家编辑</b>
    <hr/>
    <form class="form-horizontal">
        <div class="form-inline" style="padding-left:27px">
            <label for="id">编号</label>
            <input class="form-control" style="width:400px;" type="text" id="id" value="{{ merchant_info.id }}" disabled/>
        </div><br />
        <div class="form-inline">
            <label for="company">公司名称</label>
            <input class="form-control" style="width:400px;" type="text" id="company" value="{{ merchant_info.factory_name }}" />
            <span style="color:red;">*必填</span>
        </div><br />
        <div class="form-inline" style="padding-left:12px">
            <label for="connectPerson" style="vertical-align: top;">联系人</label>
            <input class="form-control" style="width:400px;" type="text" id="connectPerson" value="{{ merchant_info.contacts }}" />
            <input type="text" style="display:none" id="temp_id">
        </div><br />
        <div class="form-inline">
            <label for="tel">联系方式</label>
            <input class="form-control" style="width:400px;" type="text" id="tel" value="{{ merchant_info.contact_way }}" />
            <span style="display:none;">*必填</span>
        </div><br />
        <div class="form-inline" style="padding-left:27px">
            <label for="comment">备注</label>
            <input class="form-control" style="width:400px;" type="text" id="comment" value="{{ merchant_info.comment }}" />
            <span style="display:none;">*必填</span>
        </div>
        <input type="text" id="operator" value="{{ request.session.username }}" style="display: none;">
    </form>
    <div style="padding-left: 100px;">
        <button type="button" class="btn btn-primary" id="item_edit">
            提交
        </button>&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default" id="edit_cancel">
            取消
        </button>
    </div>
</div>

<script type="text/javascript">
$("#item_edit").click(function(){
    var id = $("#id").val();
    var company = $("#company").val();
    if(!company || company == ''){
        alert('公司名称不能为空');
        return;
    }
    var connectPerson = $("#connectPerson").val();
    var tel = $("#tel").val();
    var comment = $("#comment").val();
    var operator = $("#operator").val();

    var urls = "{% url 'equipment:meditaction' %}";
    var postdata = {id:id,factory_name:company, contacts:connectPerson, contact_way:tel, comment:comment, operator:operator}
    var jsonstr = $.ajax({
			url : urls,
			type : "POST",
			data : postdata,
			async : false,
			cache : false
		});
		var jsonobj = eval('(' + jsonstr.responseText + ')');
		if(jsonobj.status==0){
		    alert(jsonobj.message);
		}else{
            window.location.href="{% url 'equipment:merchantinfo' %}?page=" + {{ page }};
        }
});

$("#edit_cancel").click(function(){
    window.location.href="{% url 'equipment:merchantinfo' %}?page=" + {{ page }};
});
</script>
{% endblock %}